﻿using Hangfire;
using Microsoft.Extensions.DependencyInjection;

namespace LJ.TaskScheduler.Hangfire;

public class HangfireTaskSchedulerJobActivator(IServiceProvider serviceProvider) : JobActivator
{
    private readonly IServiceProvider _serviceProvider = serviceProvider;

    public override object ActivateJob(Type type)
    {
        using var scope = _serviceProvider.CreateScope();
        return scope.ServiceProvider.GetRequiredService(type);
    }
}